<template>
<uni-shadow-root class="partials-assistance_list-index"><block v-if="(!receiveData.androidTemplate||receiveData.androidTemplate=='typeOne')">
  <scroll-view scroll-y class="assistance_list" v-if="assistanceList&&assistanceList.length!=0">
          <view v-for="(assistanceItem,index) in (assistanceList)" :key="assistanceItem.index" class="assistance_item" v-if="limitState?limitState>index:'true'" :data-link="'assistances_detail.html?needLogin=1&assistanceId='+(assistanceItem.id)" @click="tolinkUrl">
              <view class="assistance_item_left">
                  <image class="assistance_item_banner" mode="aspectFill" :src="assistanceItem.topImage"></image>
                  
              </view>
              <view class="assistance_item_right">
                  <text class="assistance_item_name">{{assistanceItem.title}}</text>
                  <text class="assistance_item_description">成功次数：{{assistanceItem.successCount}}次</text>
                  <text class="assistance_item_description">浏览人数：{{assistanceItem.viewCount}}人</text>
                  <view class="assistance_item_bottom">
                      <view class="assistance_item_time">
                          <image class="assistance_item_time_icon" src="https://image1.sansancloud.com/xianhua/2020_3/5/15/11/46_82.jpg?x-oss-process=style/preview_120"></image>
                          <text class="assistance_item_time_value">{{assistanceItem.startDatetime}}~{{assistanceItem.endDatetime}}</text>
                      </view>
                      
                  </view>
              </view>
          </view>
      </scroll-view>
      <view class="noproduct" v-else :style="'margin-top:'+(limitState!=0?'0rpx':'200rpx')">
        <image mode="widthFix" src="https://image1.sansancloud.com/xianhua/2019_12/16/15/54/55_950.jpg?x-oss-process=style/preview_120"></image>
        <text>没有相关课程</text>
      </view>
</block>
<block v-if="receiveData.androidTemplate == 'typeTwo'">
  
</block></uni-shadow-root>
</template>

<script>

global['__wxRoute'] = 'partials/assistance_list/index'
const app = getApp();
Component({
  properties: {
    receiveData: {
      type: Object,
      value: 'default value',
    },
  },
  data: {
    setting: null, 
    assistanceList: null,
    limitState:0,
    params:null,
    listPage:{
        page: 1,
        pageSize: 20,
        totalSize: 0,
    },
  },
  ready: function () {
    let that = this;
    console.log("====assistanceList-data=====", that.data.receiveData);
    that.initSetting();
    if (that.data.receiveData.jsonData ) {
        that.data.params=Object.assign({},that.data.params,that.data.receiveData.jsonData)
        that.getData(that.data.params)
        if(that.data.receiveData.jsonData.count){
            that.setData({ limitState: that.data.receiveData.jsonData.count })
        }
    }
    console.log("====assistanceList-limitState=====", that.data.limitState)
    console.log("====assistanceList-params=====", that.data.params)
  },
  methods: {
    setDataFun:function(data){
        let that=this;
        console.log("setDataFun",data)
        that.setData({params: data})
        that.getData(data)
    },
    /* 获取数据 */
    getData: function (param) {
      var that = this
      var customIndex = app.globalData.AddClientUrl("/wx_find_assistances.html", param)
      app.globalData.showToastLoading('loading', true)
      wx.request({
        url: customIndex.url,
        header: app.globalData.header,
        success: function (res) {
          wx.hideLoading()
          console.log(res.data)
          let data=res.data.relateObj.result
          that.data.listPage.pageSize = res.data.relateObj.pageSize
          that.data.listPage.page = res.data.relateObj.curPage
          that.data.listPage.totalSize = res.data.relateObj.totalSize
          let dataArr = that.data.assistanceList;
          for(let i=0;i<data.length;i++){
              data[i].endDatetime=data[i].endDatetime.slice(5)
              data[i].startDatetime=data[i].startDatetime.slice(5)
          }
          console.log("===data====",data)
          if (param.page == 1) {
            dataArr = []
          }
          if (!data || data.length == 0) {
            that.setData({ assistanceList: [] })
          } else {
            if (dataArr == null) { dataArr = [] }
            dataArr = dataArr.concat(data)
            that.setData({ assistanceList: dataArr })
          }
          wx.hideLoading()
        },
        fail: function (res) {
          console.log("fail")
          wx.hideLoading()
          app.globalData.loadFail()
        }
      })
    },
    calling: function (e) {
      console.log('====e===', e)
      let phoneNumber = e.currentTarget.dataset.phonenumber
      wx.makePhoneCall({
        phoneNumber: phoneNumber, //此号码并非真实电话号码，仅用于测试
        success: function () {
          console.log("拨打电话成功！")
        },
        fail: function () {
          console.log("拨打电话失败！")
        }
      })
    },
    toIndex() {
      app.globalData.toIndex()
    },
    tolinkUrl: function (e) {
      let linkUrl = e.currentTarget.dataset.link
      app.globalData.linkEvent(linkUrl)
    },
    initSetting() {
      this.setData({ setting: app.globalData.setting })
    },
    onPullDownRefresh: function () {
      this.data.params.name = ""
      this.data.listPage.page = 1
      this.data.params.page = 1
      this.getData(this.data.params)

    },
    onReachBottom: function () {
      var that = this
      if (that.data.listPage.totalSize > that.data.listPage.curPage * that.data.listPage.pageSize) {
        that.data.listPage.page++
        that.data.params.page++
        that.getData(that.data.params);
      }else{
          wx.showToast({
            title: "到底了~",
            image: '/wxcomponents/images/icons/tip.png',
            duration: 1000
          });
      }
    },
  }
})
export default global['__wxComponents']['partials/assistance_list/index']
</script>
<style platform="mp-weixin">
@import 'type_one/index.css';
</style>